<template>
  <div>
    <common-login :checks="false" @toLogin="login" @getCode="getCode" ref="login"/>
  </div>
</template>

<script>
import commonLogin from '@/components/commonLogin'
import api from '@/api'
export default {
  name: 'login',
  data () {
    return {}
  },
  methods: {
    login (data) {
      let params = {
        ver_number: data.code,
        ver_phone: data.phone
      }
      api.platformLogin({
        params,
        callback: res => {
          if (res.data.error_code === 0) {
            this.$toast.success({
              message: res.data.message,
              duration: 1000,
              forbidClick: true
            })
            this.user = res.data.data
            window.sessionStorage.setItem('user', JSON.stringify(res.data.data))
            this.$router.push('/my')
          } else {
            this.$toast(res.data.message)
            this.$refs['login'].setLoading()
          }
        }
      })
    },

    getCode (phone) {
      api.getPlatformCode({
        params: {phone, type: '1'},
        callback: res => {
          this.$toast(res.data.message)
          this.$refs['login'].setCodeStatus(res.data.error_code === 0)
        }
      })
    }
  },
  components: {
    commonLogin
  },
  created () {
  }
}
</script>

<style scoped>
  .container{
    padding: 0 15px;
  }
</style>
